home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / frasr182.zip / PLOT3D.C < prev    next >
Text File  |  1992-12-13  |  14KB  |  454 lines

  1. /*
  2.     This file includes miscellaneous plot functions and logic
  3.     for 3D, used by lorenz.c and line3d.c
  4.     By Tim Wegner and Marc Reinig.
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include "fractint.h"
  10. #include "fractype.h"
  11. #include "prototyp.h"
  12.  
  13. /* Use these palette indices for red/blue - same on ega/vga */
  14. #define PAL_BLUE    1
  15. #define PAL_RED 2
  16. #define PAL_MAGENTA 3
  17.  
  18. extern void (_fastcall * standardplot)(int,int,int);
  19. extern int Targa_Out, sxoffs, syoffs;
  20.  
  21. int whichimage;
  22. extern int fractype;
  23. extern int mapset;
  24. extern int xadjust;
  25. extern int yadjust;
  26. extern int xxadjust;
  27. extern int yyadjust;
  28. extern int xshift;
  29. extern int yshift;
  30. extern char MAP_name[];
  31. extern int init3d[];
  32. extern int xdots;
  33. extern int ydots;
  34. extern int colors;
  35. extern BYTE dacbox[256][3];
  36. extern int debugflag;
  37.  
  38. extern int max_colors;
  39.  
  40. int xxadjust1;
  41. int yyadjust1;
  42. int eyeseparation = 0;
  43. int glassestype = 0;
  44. int xshift1;
  45. int yshift1;
  46. int xtrans = 0;
  47. int ytrans = 0;
  48. int red_local_left;
  49. int red_local_right;
  50. int blue_local_left;
  51. int blue_local_right;
  52. int red_crop_left   = 4;
  53. int red_crop_right  = 0;
  54. int blue_crop_left  = 0;
  55. int blue_crop_right = 4;
  56. int red_bright      = 80;
  57. int blue_bright     = 100;
  58.   
  59. BYTE T_RED;
  60.  
  61. /* Bresenham's algorithm for drawing line */
  62. void _fastcall draw_line (int X1, int Y1, int X2, int Y2, int color)
  63.  
  64. {               /* uses Bresenham algorithm to draw a line */
  65.     int dX, dY;                     /* vector components */
  66.     int row, col,
  67.         final,                      /* final row or column number */
  68.         G,                  /* used to test for new row or column */
  69.         inc1,           /* G increment when row or column doesn't change */
  70.         inc2;               /* G increment when row or column changes */
  71.     char pos_slope;
  72.     extern int xdots,ydots;
  73.  
  74.     dX = X2 - X1;                   /* find vector components */
  75.     dY = Y2 - Y1;
  76.     pos_slope = (dX > 0);                   /* is slope positive? */
  77.     if (dY < 0)
  78.     pos_slope = !pos_slope;
  79.     if (abs (dX) > abs (dY))                /* shallow line case */
  80.     {
  81.         if (dX > 0)         /* determine start point and last column */
  82.         {
  83.             col = X1;
  84.             row = Y1;
  85.             final = X2;
  86.         }
  87.         else
  88.         {
  89.             col = X2;
  90.             row = Y2;
  91.             final = X1;
  92.         }
  93.         inc1 = 2 * abs (dY);            /* determine increments and initial G */
  94.         G = inc1 - abs (dX);
  95.         inc2 = 2 * (abs (dY) - abs (dX));
  96.         if (pos_slope)
  97.             while (col <= final)    /* step through columns checking for new row */
  98.             {
  99.                 (*plot) (col, row, color);
  100.                 col++;
  101.                 if (G >= 0)             /* it's time to change rows */
  102.                 {
  103.                     row++;      /* positive slope so increment through the rows */
  104.                     G += inc2;
  105.                 }
  106.                 else                        /* stay at the same row */
  107.                     G += inc1;
  108.             }
  109.         else
  110.             while (col <= final)    /* step through columns checking for new row */
  111.             {
  112.                 (*plot) (col, row, color);
  113.                 col++;
  114.                 if (G > 0)              /* it's time to change rows */
  115.                 {
  116.                     row--;      /* negative slope so decrement through the rows */
  117.                     G += inc2;
  118.                 }
  119.                 else                        /* stay at the same row */
  120.                     G += inc1;
  121.             }
  122.     }   /* if |dX| > |dY| */
  123.     else                            /* steep line case */
  124.     {
  125.         if (dY > 0)             /* determine start point and last row */
  126.         {
  127.             col = X1;
  128.             row = Y1;
  129.             final = Y2;
  130.         }
  131.         else
  132.         {
  133.             col = X2;
  134.             row = Y2;
  135.             final = Y1;
  136.         }
  137.         inc1 = 2 * abs (dX);            /* determine increments and initial G */
  138.         G = inc1 - abs (dY);
  139.         inc2 = 2 * (abs (dX) - abs (dY));
  140.         if (pos_slope)
  141.             while (row <= final)    /* step through rows checking for new column */
  142.             {
  143.                 (*plot) (col, row, color);
  144.                 row++;
  145.                 if (G >= 0)                 /* it's time to change columns */
  146.                 {
  147.                     col++;  /* positive slope so increment through the columns */
  148.                     G += inc2;
  149.                 }
  150.                 else                    /* stay at the same column */
  151.                     G += inc1;
  152.             }
  153.         else
  154.             while (row <= final)    /* step through rows checking for new column */
  155.             {
  156.                 (*plot) (col, row, color);
  157.                 row++;
  158.                 if (G > 0)                  /* it's time to change columns */
  159.                 {
  160.                     col--;  /* negative slope so decrement through the columns */
  161.                     G += inc2;
  162.                 }
  163.                 else                    /* stay at the same column */
  164.                     G += inc1;
  165.             }
  166.     }
  167. }   /* draw_line */
  168.  
  169.  
  170. /* use this for continuous colors later */
  171. void _fastcall plot3dsuperimpose16b(int x,int y,int color)
  172. {
  173.     int tmp;
  174.     if (color != 0)         /* Keeps index 0 still 0 */
  175.     {
  176.         color = colors - color; /*  Reverses color order */
  177.         color = color / 4;
  178.         if(color == 0)
  179.             color = 1;
  180.     }
  181.     color = 3;
  182.     tmp = getcolor(x,y);
  183.  
  184.     /* map to 4 colors */
  185.     if(whichimage == 1) /* RED */
  186.     {
  187.         if(red_local_left < x && x < red_local_right)
  188.         {
  189.             putcolor(x,y,color|tmp);
  190.             if (Targa_Out)                              
  191.                 targa_color(x, y, color|tmp);
  192.         }
  193.     }
  194.     else if(whichimage == 2) /* BLUE */
  195.         if(blue_local_left < x && x < blue_local_right)
  196.         {
  197.             color = color <<2;
  198.             putcolor(x,y,color|tmp);
  199.             if (Targa_Out)                              
  200.                 targa_color(x, y, color|tmp);
  201.         }
  202. }
  203.  
  204. void _fastcall plot3dsuperimpose16(int x,int y,int color)
  205. {
  206.     int tmp;
  207.  
  208.     tmp = getcolor(x,y);
  209.  
  210.     if(whichimage == 1) /* RED */
  211.     {
  212.         color = PAL_RED;
  213.         if(tmp > 0 && tmp != color)
  214.             color = PAL_MAGENTA;
  215.         if(red_local_left < x && x < red_local_right)
  216.         {
  217.             putcolor(x,y,color);
  218.             if (Targa_Out)                              
  219.                 targa_color(x, y, color);
  220.         }
  221.     }
  222.     else if(whichimage == 2) /* BLUE */
  223.         if(blue_local_left < x && x < blue_local_right)
  224.         {
  225.             color = PAL_BLUE;
  226.             if(tmp > 0 && tmp != color)
  227.                 color = PAL_MAGENTA;
  228.             putcolor(x,y,color);
  229.             if (Targa_Out)                              
  230.                 targa_color(x, y, color);
  231.         }
  232. }
  233.  
  234.  
  235. void _fastcall plot3dsuperimpose256(int x,int y,int color)
  236. {
  237.     int tmp;
  238.     BYTE t_c;
  239.  
  240.     t_c = 255-color;
  241.  
  242.     if (color != 0)         /* Keeps index 0 still 0 */
  243.     {
  244.         color = colors - color; /*  Reverses color order */
  245.         if (max_colors == 236)
  246.         color = 1 + color / 21; /*  Maps colors 1-255 to 13 even ranges */
  247.         else
  248.         color = 1 + color / 18; /*  Maps colors 1-255 to 15 even ranges */
  249.     }
  250.  
  251.     tmp = getcolor(x,y);
  252.     /* map to 16 colors */
  253.     if(whichimage == 1) /* RED */
  254.     {
  255.         if(red_local_left < x && x < red_local_right)
  256.         {
  257.             /* Overwrite prev Red don't mess w/blue */
  258.             putcolor(x,y,color|(tmp&240));
  259.             if (Targa_Out)
  260.                 if (!ILLUMINE)
  261.                     targa_color(x, y, color|(tmp&240));
  262.                 else
  263.                     targa_writedisk (x+sxoffs, y+syoffs, t_c, 0, 0);
  264.         }
  265.     }
  266.     else if(whichimage == 2) /* BLUE */
  267.         if(blue_local_left < x && x < blue_local_right)
  268.         {
  269.             /* Overwrite previous blue, don't mess with existing red